// Requires Model to be loaded first
// View-relate

function View_init()
{
    initDocumentElements();
}

function initDocumentElements()
{
	$$('#Scrapbook li').each(function (elmt){
		Scrap_activateWrapper(elmt, false);
	});

	$$('#listBookmarks li .bookmark').each(function (elmt){
		Bookmark_activate(elmt);
	});

	$$('.minimized').each(function (elmt){
		activateMinimized(elmt);
	});

        $('DocFilename').innerHTML= getCurrentFilename();
        new Proto.EIP( {type: 'text', item:$('DocFilename'), postSave: fileChange,
                        preEdit:removeExtension, autoselect:true} );

        $('DocTitle').innerHTML = document.title;
        new Proto.EIP( {type: 'text', item:$('DocTitle'), postSave: titleChange, autoselect:true} );

        $('textareaScrap').observe('keypress', ScrapEntry_handlerKeypress);

        var elmt = $('dropdownAddMode');
        elmt.selectedIndex = 0;

        $('textareaScrap').select();

        //Select a current line
        $$('.current').each(function(elmt) {gxCurrentScrap = elmt;});
        if(!gxCurrentScrap){
            gxCurrentScrap = $('Scrapbook').down('.wrapper');
        }

        if(gxCurrentScrap){
            if(!gxCurrentScrap.visible())
                CurrentScrap_reset();
            else
                intelliScroll(gxCurrentScrap);
        }

        gbHideIcons? Controls_hide(): Controls_show();
        gbShowInfo? InfoDisplay_show(): InfoDisplay_hide();
        gbNumbering? Numbering_on(): Numbering_off();

        NotebookList_render();
}

function displayNotebookInList(file)
{
    var addToLocation=$('listNotebooks');

    var notebook = document.createElement('a');
    notebook.addClassName('notebook');

    var item = document.createElement('li');

    var button = document.createElement('img');
    button.setAttribute('src', gsAppDir + 'notebook.png');
    button.setAttribute('class', gsAppDir + 'iconNotebook');
    button.setAttribute('title', gsAppDir + 'Click for menu.');

    notebook.setAttribute('href', file);
    notebook.insert(file);
    item.insert({top:notebook});
    item.insert({top:button});
    addToLocation.insert({bottom:item});
}

function NotebookList_render()
{
    for(var i=0; i< gasNotebooks.length; i++)
        displayNotebookInList(gasNotebooks[i]);
}


